var tsc_tools=function(parent){
	this.parent=parent;
	this.domObj=false;
	this.errors=[];
	

	this.init=function(){
	  //Найти дом обхект контейнер
	  var t=document.getElementById( this.parent.config.toolsId );
	  if( typeof(t)=='undefined' || !t ) return this.err('DOM object for Tools undefined');
		this.domObj=t;
		//Построить и инициировать элементы
		return true;
	}
	
	if(!this.init()) return false;

	this.init_project=function(){

	}
	
	this.err=function(txt){
	  this.errors.push(txt);
	  return false;
	}
}

//Класс абстрактного элемента.
element = newClass(null, {
	debug:true,
	debug:function(debug){this.debug=debug},
  constructor: function(options){
    this.id=options.id;
    if(this.debug)console.log("element.constructor() "+this.id);
    return true;
  },
  show:function(){
		//VIRTUAL
    if(this.debug)console.log("- VIRTUAL element.show() "+this.id);
    return false;
	}
});

//Класс Контейнерного элемента.
container = newClass(element, {
  constructor: function(options) {
    this.collection=[];
    if(!this.constructor.prototype.constructor.call(this,options))return false;
    if(this.debug)console.log("container.constructor() "+this.id);
    return true;
  },
  add:function(elm){
    if( ! elm instanceof element ) return false;
    this.collection.push(elm);
    return true;
	},
	show:function(){
	  var content='';
	  //for( var i in this.collection )
	  for( var i=0; i<this.collection.length; i++ )	content+=this.collection[i].show();
	  return '<div class="container" id="'+this.id+'">'+content+'</div>';
	}
});

//Класс кнопки элемента.
button = newClass(element, {
  constructor: function(options){
    this.options={
			icon:false,
			label:false,
			action:false,
			className:false
		};
    for( var i in this.options )if( typeof( options[i] )!=='undefined' ) this.options[i]=options[i];

    this.constructor.prototype.constructor.call(this,options);
    if(this.debug)console.log("button.constructor() "+this.id);
  },
  show:function(){
    if(this.debug)console.log("button.show() "+this.id);
		console.log(this.options);
		if(this.options.action){
		  if(typeof(window.ts_tb_actions)=='undefined')window.ts_tb_actions={};
		  window.ts_tb_actions['func_'+this.id]=this.options.action;
		}
    return '<a href="#" class="button'+((this.options.className)?' '+this.options.className:'')+'" '+
      ' id="'+ this.id +'"'+
			( (this.options.label)?' title="'+this.options.label+'"':'' ) +
			( (this.options.action)?' onClick="window.ts_tb_actions.func_'+ this.id +'(); return false;"':'' ) +
			'>'+ (this.options.icon?'<i class="icon icon-'+this.options.icon+'">'+this.options.icon+'</i>':this.options.label) +'</a>'+"\n";
	}
});


//Класс Тулбара элемента.
toolbar = newClass(container, {
  constructor: function(options) {
    this.dom=document.getElementById(options.containerId);
    if(!this.constructor.prototype.constructor.call(this,options))return false;
    if(this.debug)console.log("container.constructor() "+this.id);
    return true;
  },
	show:function(){
	  var content=this.constructor.prototype.constructor.call();
	  this.dom.innerHTML=content;
	}
});
